// pages/member/checkeBox/checkeBox.js
Page({
  data: {
    allChecked: false,
    checkData: [{
        value: 'USA',
        name: '美国'
      },
      {
        value: 'CHN',
        name: '中国',
        checked: 'true'
      },
      {
        value: 'BRA',
        name: '巴西'
      },
      {
        value: 'JPN',
        name: '日本'
      },
      {
        value: 'ENG',
        name: '英国'
      },
      {
        value: 'FRA',
        name: '法国'
      }
    ]
  },
  // 多选框选择
  checkboxChange(e) {
    let checkData = this.data.checkData
    let values = e.detail.value
    checkData.forEach(item => {
      item.checked = false
      for (let sonItem of values) {
        if (item.value === sonItem) {
          item.checked = true
          break;
        }
      }
    })
    this.setData({
      checkData: checkData,
      allChecked: checkData.length == values.length
    })
  },
  // 全选点击
  selectAll() {
    let checkData = this.data.checkData
    checkData.forEach(item => {
      item.checked = !this.data.allChecked
    })
    this.setData({
      allChecked: !this.data.allChecked,
      checkData: checkData
    })
  },
  // 提交按钮
  submitSelect() {
    let selectList = this.data.checkData.filter(item => {
      return item.checked
    })
    console.log(selectList)
  }
})